package com.shop.trade.api.controller;


import com.shop.common.model.PayCallMdel;
import com.shop.common.model.PayModel;
import com.shop.common.util.SessionUtils;
import com.shop.common.util.excption.UserNotFoundException;
import com.shop.trade.api.service.IAliPaySvc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description:
 *
 * @author zhoulk
 * @date: 2019年04月17日  16:04
 */

@RefreshScope
@RequestMapping(value = "/trade")
@Controller
public class AliPayController {

    @Autowired
    IAliPaySvc iAliPaySvc;
    @Autowired
    SessionUtils sessionUtils;
    @Value("${zlk.test}")
    String test;


    @GetMapping("/test")
    public @ResponseBody
    String test() {
        return test;
    }

    @GetMapping(value = "/payToUser")
    public void payToUser(HttpServletRequest request) throws UserNotFoundException {
        Integer userId = sessionUtils.USER_ID(request);
        iAliPaySvc.payToUser(null);
    }

    @GetMapping(value = "/aliPayPage")
    public void toPayPage(PayModel payModel, HttpServletResponse response) throws IOException {
        iAliPaySvc.toPayPage(payModel, response);
    }

    @GetMapping(value = "/aliPayCall")
    public void aliPayCall(PayCallMdel payCallMdel, HttpServletResponse response) throws IOException {
        iAliPaySvc.aliPayCall(payCallMdel, response);
    }

    @GetMapping(value = "/aliPayCall2")
    public void aliPayCall2(PayCallMdel payCallMdel, HttpServletResponse response) throws IOException {
        iAliPaySvc.aliPayCall2(payCallMdel, response);
    }
}
